<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Models\User;

class NotifiMsg extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    public function toDatabase($notifiable) {
        // 存入数据库里的数据
        $end_time = date('Y年m月d日',$this->user->member_end_time);
        if($this->user->is_member){
            $title = '会员办理成功';
            $content = "恭喜您已成功成为会员，您的会员卡截止日期为{$end_time}，我们将提供优质的服务。";

        }else{
            $title = '会员已取消';
            $content = '您的会员已取消，建议重新充值或续费，继续享受优质服务';
        }
        return [
            'user_id' => $this->user->id,
            'title' => $title,
            'content' => $content,
            'noti_at' => date('Y-m-d H:i:s'), 
        ]; 
    }
    
}
